using Infrastructure.Attribute;
using Infrastructure.Extensions;
using JTZY.Model.Store.Dto;
using JTZY.Model.Store;
using JTZY.Repository;
using JTZY.Service.Store.IStoreService;

namespace JTZY.Service.Store
{
    /// <summary>
    /// 打印机列表Service业务层处理
    /// </summary>
    [AppService(ServiceType = typeof(ICorecmsprinterService), ServiceLifetime = LifeTime.Transient)]
    public class CorecmsprinterService : BaseService<Corecmsprinter>, ICorecmsprinterService
    {
        /// <summary>
        /// 查询打印机列表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<CorecmsprinterDto> GetList(CorecmsprinterQueryDto parm)
        {
            var predicate = QueryExp(parm);

            var response = Queryable()
                .Where(predicate.ToExpression())
                .ToPage<Corecmsprinter, CorecmsprinterDto>(parm);

            return response;
        }


        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Corecmsprinter GetInfo(long Id)
        {
            var response = Queryable()
                .Where(x => x.UserId == Id)
                .First();

            return response;
        }

        /// <summary>
        /// 添加打印机列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Corecmsprinter AddCorecmsprinter(Corecmsprinter model)
        {
            return Insertable(model).ExecuteReturnEntity();
        }

        /// <summary>
        /// 修改打印机列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateCorecmsprinter(Corecmsprinter model)
        {
            return Update(model, true);
        }

        /// <summary>
        /// 查询导出表达式
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        private static Expressionable<Corecmsprinter> QueryExp(CorecmsprinterQueryDto parm)
        {
            var predicate = Expressionable.Create<Corecmsprinter>();

            return predicate;
        }
    }
}